package com.yoomiito.app.widget.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yoomiito.app.R;
import com.yoomiito.app.listener.OnViewClickListener;
import com.yoomiito.app.model.bean.AreaInfo;
import com.yoomiito.app.model.gift.GiftGoodsList;
import com.yoomiito.app.model.home.FreeBuyActInfo;
import com.yoomiito.app.model.home.FreeGoodsInfo;
import com.yoomiito.app.net.YmApi;

import java.util.List;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

/**
 * 0元购
 */
public class AreaDialog extends BaseDialog implements View.OnClickListener {
    private OnClickListener mOnViewClickListener;
    RecyclerView recyclerView;

    List<AreaInfo> infoList;

    public AreaDialog(@NonNull Context context) {
        this(context, 0);
    }

    public AreaDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.dialog_2);
    }

    @Override
    public View setView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_area, null, false);
        recyclerView = view.findViewById(R.id.rv_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        if (infoList != null) {
            AreaAdapter adapter = new AreaAdapter(infoList);
            recyclerView.setAdapter(adapter);
            adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter1, View view, int position) {
                    if (mOnViewClickListener != null) {
                        mOnViewClickListener.onClick(adapter.getData().get(position).getAreaCode());
                    }
                }
            });
        }
        return view;
    }


    public void setData(List<AreaInfo> infoList) {
        this.infoList = infoList;


    }


    static class AreaAdapter extends BaseQuickAdapter<AreaInfo, BaseViewHolder> {


        public AreaAdapter(@Nullable List<AreaInfo> data) {
            super(R.layout.item_area, data);
        }

        @Override
        protected void convert(BaseViewHolder helper, AreaInfo item) {

            helper.setText(R.id.tv_content, "+" + item.getAreaCode() + item.getAreaName());
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cancel:
                dismiss();
                break;
            case R.id.bg_now_buy:

                break;
        }
    }

    public void setOnViewClickListener(OnClickListener onViewClickListener) {
        mOnViewClickListener = onViewClickListener;
    }

    public interface OnClickListener {
        void onClick(String area);
    }


}
